/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ifpb.banco.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Vanderlan
 */
@Entity
@Table(catalog = "", schema = "VANDERLAN")
@SequenceGenerator(name = "S_VENDA_PK", sequenceName = "S_VENDA_PK")
public class Venda extends Identificavel {
    private static final long serialVersionUID = 1L;

    @Id
    @Basic(optional = false)
    @Column(name = "COD_VENDA", nullable = false, precision = 0, scale = -127)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "S_VENDA_PK")
    protected Long id;
    @Basic(optional = false)
    @Column(nullable = false, precision = 10, scale = 2)
    private BigDecimal valor;
    @Basic(optional = false)
    @Column(nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date data;
    @Basic(optional = false)
    @Column(name = "COD_CLIENTE", nullable = false)
    private BigInteger codCliente;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "venda1")
    private Venda venda;
    @JoinColumn(name = "COD_VENDA", referencedColumnName = "COD_VENDA", nullable = false, insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Venda venda1;
    @OneToMany(mappedBy = "codVenda")
    private Collection<ItensVenda> itensVendaCollection;

    public Venda() {
    }

    public Venda(Long codVenda) {
        this.id = codVenda;
    }

    public Venda(Long codVenda, BigDecimal valor, Date data, BigInteger codCliente) {
        this.id = codVenda;
        this.valor = valor;
        this.data = data;
        this.codCliente = codCliente;
    }

    public Long getCodVenda() {
        return id;
    }

    public void setCodVenda(Long codVenda) {
        this.id = codVenda;
    }

    public BigDecimal getValor() {
        return valor;
    }

    public void setValor(BigDecimal valor) {
        this.valor = valor;
    }

    public Date getData() {
        return data;
    }

    public void setData(Date data) {
        this.data = data;
    }

    public BigInteger getCodCliente() {
        return codCliente;
    }

    public void setCodCliente(BigInteger codCliente) {
        this.codCliente = codCliente;
    }

    public Venda getVenda() {
        return venda;
    }

    public void setVenda(Venda venda) {
        this.venda = venda;
    }

    public Venda getVenda1() {
        return venda1;
    }

    public void setVenda1(Venda venda1) {
        this.venda1 = venda1;
    }

    public Collection<ItensVenda> getItensVendaCollection() {
        return itensVendaCollection;
    }

    public void setItensVendaCollection(Collection<ItensVenda> itensVendaCollection) {
        this.itensVendaCollection = itensVendaCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Venda)) {
            return false;
        }
        Venda other = (Venda) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ifpb.banco.principal.entity.Venda[ codVenda=" + id + " ]";
    }
    
}
